using System;
using System.Runtime.InteropServices;
using System.Security.Permissions;
using Microsoft.SharePoint;

namespace Easy.Announcement.Features.SampleFeature
{
    /// <summary>
    /// This class handles events raised during feature activation, deactivation, installation, uninstallation, and upgrade.
    /// </summary>
    /// <remarks>
    /// The GUID attached to this class may be used during packaging and should not be modified.
    /// </remarks>

    [Guid("74e909fc-65c1-4713-a0cd-16e2996dd6fa")]
    public class SampleFeatureEventReceiver : SPFeatureReceiver
    {
        // Uncomment the method below to handle the event raised after a feature has been activated.

        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            SPWeb web = properties.Feature.Parent as SPWeb;
            SPListTemplate listTemplate = web.ListTemplates["Easy Announcement"];
            string sampleListName = "Easy Announcement";
            SPList list = web.Lists.TryGetList(sampleListName);
            if (list == null)
            {
                Guid listID = web.Lists.Add("Easy Announcement", "Sample easy announcement list", listTemplate);
                SPList newList = web.Lists[listID];

                #region Adding sample Data
                e_addSampleAnnouncement(
                    newList,
                    "US Dollar - Appreciate or Depreciate?",
                    "<img alt='' src='/_layouts/15/images/Easy.Announcement/sample/dreamstimefree_280422.jpg' style='BORDER&#58;0px solid;' />",
                    "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam condimentum dui eget enim mattis egestas. In ac accumsan enim. Nullam nec dictum mauris. Donec bibendum pellentesque nulla. Nam non ex mi. Nulla placerat ut lacus in ornare. Pellentesque at vehicula odio. Nullam neque lorem, convallis ut leo eget, aliquam rutrum lacus.",
                    "Corporate Events",
                    new DateTime(2015, 1, 1),
                    new DateTime(2020, 1, 1));

                e_addSampleAnnouncement(
                    newList,
                    "More hospital beds to be added even as primary care sector is strengthened",
                    "<img alt='' src='/_layouts/15/images/Easy.Announcement/sample/dreamstimefree_280835.jpg' style='BORDER&#58;0px solid;' />",
                    "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam condimentum dui eget enim mattis egestas. In ac accumsan enim. Nullam nec dictum mauris. Donec bibendum pellentesque nulla. Nam non ex mi. Nulla placerat ut lacus in ornare. Pellentesque at vehicula odio. Nullam neque lorem, convallis ut leo eget, aliquam rutrum lacus.",
                    "Training",
                    new DateTime(2015, 1, 1),
                    new DateTime(2020, 1, 1));

                e_addSampleAnnouncement(
                   newList,
                   "1 dead in crash involving Metra, vehicle",
                   "<img alt='' src='/_layouts/15/images/Easy.Announcement/sample/dreamstimefree_282574.jpg' style='BORDER&#58;0px solid;' />",
                   "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam condimentum dui eget enim mattis egestas. In ac accumsan enim. Nullam nec dictum mauris. Donec bibendum pellentesque nulla. Nam non ex mi. Nulla placerat ut lacus in ornare. Pellentesque at vehicula odio. Nullam neque lorem, convallis ut leo eget, aliquam rutrum lacus.",
                   "Staff Benefit",
                   new DateTime(2015, 1, 1),
                   new DateTime(2021, 1, 1));

                e_addSampleAnnouncement(
                  newList,
                  "Oracle lawyer says Google's Android generated $31 bln revenue",
                  "<img alt='' src='/_layouts/15/images/Easy.Announcement/sample/dreamstimefree_284631.jpg' style='BORDER&#58;0px solid;' />",
                  "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam condimentum dui eget enim mattis egestas. In ac accumsan enim. Nullam nec dictum mauris. Donec bibendum pellentesque nulla. Nam non ex mi. Nulla placerat ut lacus in ornare. Pellentesque at vehicula odio. Nullam neque lorem, convallis ut leo eget, aliquam rutrum lacus.",
                  "Corporate Events",
                  new DateTime(2015, 2, 1),
                  new DateTime(2021, 2, 1));

                e_addSampleAnnouncement(
                    newList,
                    "Statue of Lenin pulled down in Ukraine's Kharkiv",
                    "<img alt='' src='/_layouts/15/images/Easy.Announcement/sample/dreamstimefree_284980.jpg' style='BORDER&#58;0px solid;' />",
                    "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam condimentum dui eget enim mattis egestas. In ac accumsan enim. Nullam nec dictum mauris. Donec bibendum pellentesque nulla. Nam non ex mi. Nulla placerat ut lacus in ornare. Pellentesque at vehicula odio. Nullam neque lorem, convallis ut leo eget, aliquam rutrum lacus.",
                    "Promotion",
                    new DateTime(2015, 1, 1),
                    new DateTime(2018, 1, 1));

                e_addSampleAnnouncement(
                    newList,
                    "Child Growth and Development",
                    "<img alt='' src='/_layouts/15/images/Easy.Announcement/sample/dreamstimefree_286390.jpg' style='BORDER&#58;0px solid;' />",
                    "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam condimentum dui eget enim mattis egestas. In ac accumsan enim. Nullam nec dictum mauris. Donec bibendum pellentesque nulla. Nam non ex mi. Nulla placerat ut lacus in ornare. Pellentesque at vehicula odio. Nullam neque lorem, convallis ut leo eget, aliquam rutrum lacus.",
                    "Staff Benefit",
                    new DateTime(2015, 1, 1),
                    new DateTime(2018, 1, 1));

                e_addSampleAnnouncement(
                    newList,
                    "On board a ghost ship",
                    "<img alt='' src='/_layouts/15/images/Easy.Announcement/sample/dreamstimefree_288189.jpg' style='BORDER&#58;0px solid;' />",
                    "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam condimentum dui eget enim mattis egestas. In ac accumsan enim. Nullam nec dictum mauris. Donec bibendum pellentesque nulla. Nam non ex mi. Nulla placerat ut lacus in ornare. Pellentesque at vehicula odio. Nullam neque lorem, convallis ut leo eget, aliquam rutrum lacus.",
                    "Workspace Safety",
                    new DateTime(2015, 4, 1),
                    new DateTime(2018, 1, 1));
                #endregion
            }
        }


        private void e_addSampleAnnouncement(SPList list, string title, string img, string summary, string cat, DateTime pub, DateTime exp)
        {
            SPListItem newItem = list.AddItem();
            newItem["Title"] = title;
            newItem["PublishingRollupImage"] = img;
            newItem["Summary"] = summary;
            newItem["EasyCategory"] = cat;
            newItem["PublishDate"] = pub;
            newItem["ExpiryDate"] = exp;
            newItem.Update();
        }
    }
}
